from OptionsPage import OptionsPage
from Autotests.LocalMachine.UiObjectsMap.AirClient import Options
from Autotests.LocalMachine.Controls import *


class BandwidthTab(OptionsPage):
    def __init__(self):
        super(BandwidthTab, self).__init__()
        self._frame = BaseWebControl(Options.Bandwidth.frame)
        self._checkboxLimit = WebDefaultCheckBox(Options.Bandwidth.checkboxLimit)
        self._checkboxNoLimitOnSatSun = WebDefaultCheckBox(Options.Bandwidth.checkboxWeekendLimit)
        self._txtTurnOnAt = WebLineEdit(Options.Bandwidth.txtTurnOnTime)
        self._txtTurnOffAt = WebLineEdit(Options.Bandwidth.txtTurnOffTime)
        self._txtUploadSpeed = WebLineEdit(Options.Bandwidth.txtUploadSpeed)
        self._txtDownloadSpeed = WebLineEdit(Options.Bandwidth.txtDownloadSpeed)

    def goToHomeLocation(self):
        super(BandwidthTab, self).goToHomeLocation()
        WebButton(Options.btnBandwidth).click()

    @OptionsPage.setter
    def clearBandwidthSettings(self):
        if self._checkboxLimit.isChecked():
            self._checkboxLimit.setCheckState(False)

    @OptionsPage.setter
    def setBandwidthSettings(self, turnOnTime, turnOffTime, uploadSpeed, downloadSpeed):
        self._checkboxLimit.setCheckState(True)
        self._txtTurnOnAt.typeText(turnOnTime)
        self._txtTurnOffAt.typeText(turnOffTime)
        self._txtUploadSpeed.typeText(uploadSpeed)
        self._txtDownloadSpeed.typeText(downloadSpeed)
        self._checkboxNoLimitOnSatSun.setCheckState(True)

    @OptionsPage.getter
    def getBandwidthSettings(self):
        return self._txtTurnOnAt.text(), self._txtTurnOffAt.text(),\
               self._txtUploadSpeed.text(), self._txtDownloadSpeed.text()
